Index: grade/edit/letter/edit.php
=========================================================
--- grade/edit/letter/edit.php	(revision 1.3.2.1)
+++ grade/edit/letter/edit.php	Mon Feb 09 08:35:59 CET 2009
@@ -133,12 +133,7 @@
     admin_externalpage_print_header();
 
 } else {
-    $navigation = grade_build_nav(__FILE__, $pagename, $COURSE->id);
-    /// Print header
-    print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($COURSE));
-
-    $currenttab = 'lettersedit';
-    require('tabs.php');
+    print_grade_page_head($COURSE->id, 'letter', 'edit', get_string('editgradeletters', 'grades'));
 }
 
 $mform->display();
Index: grade/edit/letter/index.php
=========================================================
--- grade/edit/letter/index.php	(revision 1.4)
+++ grade/edit/letter/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -45,15 +45,7 @@
 $strgrades = get_string('grades');
 $pagename  = get_string('letters', 'grades');
 
-$navigation = grade_build_nav(__FILE__, $pagename, $courseid);
-
-/// Print header
-print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
-/// Print the plugin selector at the top
-print_grade_plugin_selector($courseid, 'edit', 'letter');
-
-$currenttab = 'lettersview';
-require('tabs.php');
+print_grade_page_head($courseid, 'letter', 'view', get_string('gradeletters', 'grades'));
 
 $letters = grade_get_letters($context);
 
Index: grade/edit/outcome/course.php
=========================================================
--- grade/edit/outcome/course.php	(revision 1.6.2.1)
+++ grade/edit/outcome/course.php	Mon Feb 09 08:35:59 CET 2009
@@ -132,26 +132,8 @@
     redirect('course.php?id='.$courseid); // we must redirect to get fresh data
 }
 
-$strgrades = get_string('grades');
-$pagename  = get_string('outcomescourse', 'grades');
-
-$navlinks = array(array('name'=>$strgrades,
-                        'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid,
-                        'type'=>'misc'),
-                  array('name'=>$pagename,
-                        'link'=>'',
-                        'type'=>'misc')
-                 );
-$navigation = build_navigation($navlinks);
-$navigation = grade_build_nav(__FILE__, $pagename, $courseid);
 /// Print header
-print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
-
-/// Print the plugin selector at the top
-print_grade_plugin_selector($courseid, 'edit', 'outcome');
-
-$currenttab = 'courseoutcomes';
-require('tabs.php');
+print_grade_page_head($COURSE->id, 'outcome', 'course');
 
 check_theme_arrows();
 require('course_form.html');
Index: grade/edit/outcome/edit.php
=========================================================
--- grade/edit/outcome/edit.php	(revision 1.4.2.2)
+++ grade/edit/outcome/edit.php	Mon Feb 09 08:35:59 CET 2009
@@ -32,9 +32,12 @@
 $id       = optional_param('id', 0, PARAM_INT);
 
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$heading = null;
 
 // a bit complex access control :-O
 if ($id) {
+    $heading = get_string('editoutcome', 'grades');
+
     /// editing existing outcome
     if (!$outcome_rec = get_record('grade_outcomes', 'id', $id)) {
         error('Incorrect outcome id');
@@ -61,6 +64,7 @@
     }
 
 } else if ($courseid){
+    $heading = get_string('addoutcome', 'grades');
     /// adding new outcome from course
     if (!$course = get_record('course', 'id', $courseid)) {
         print_error('nocourseid');
@@ -119,14 +123,8 @@
     redirect($returnurl);
 }
 
-$strgrades       = get_string('grades');
-$strgraderreport = get_string('graderreport', 'grades');
-$stroutcomeedit  = get_string('outcome', 'grades');
-
 if ($courseid) {
-    $navigation = grade_build_nav(__FILE__, $stroutcomeedit, array('courseid' => $courseid));
-    print_header_simple($strgrades.': '.$strgraderreport, ': '.$stroutcomeedit, $navigation, '', '', true, '', navmenu($course));
-
+    print_grade_page_head($courseid, 'outcome', 'edit', $heading);
 } else {
     require_once $CFG->libdir.'/adminlib.php';
     admin_externalpage_setup('outcomes');
Index: grade/edit/outcome/index.php
=========================================================
--- grade/edit/outcome/index.php	(revision 1.10.2.5)
+++ grade/edit/outcome/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -103,11 +103,11 @@
 
         if(!$deleteconfirmed){
             print_header(get_string('outcomedelete', 'grades'));
-            notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname), 
+            notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname),
                     "index.php?id={$courseid}", "index.php?id={$courseid}",
-                    array('outcomeid' => $outcome->id, 
-                        'action'=> 'delete', 
-                        'sesskey' =>  $USER->sesskey, 
+                    array('outcomeid' => $outcome->id,
+                        'action'=> 'delete',
+                        'sesskey' =>  $USER->sesskey,
                         'deleteconfirmed'=> 1)
                     );
             print_footer();
@@ -122,16 +122,9 @@
 $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
 
 if ($courseid) {
-    /// Print header
-    print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
-    /// Print the plugin selector at the top
-    print_grade_plugin_selector($courseid, 'edit', 'outcome');
 
     $caneditcoursescales = has_capability('moodle/course:managescales', $context);
 
-    $currenttab = 'outcomes';
-    require('tabs.php');
-
 } else {
     admin_externalpage_print_header();
     $caneditcoursescales = $caneditsystemscales;
@@ -139,10 +132,10 @@
 
 
 $outcomes_tables = array();
+$heading = get_string('outcomes', 'grades');
 
 if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
-
-    $return = print_heading($strcustomoutcomes, '', 2, 'main', true);
+    $return = print_heading($strcustomoutcomes, '', 3, 'main', true);
     $data = array();
     foreach($outcomes as $outcome) {
         $line = array();
@@ -180,7 +173,7 @@
                         " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
         }
         $line[] = $buttons;
-        
+
         $data[] = $line;
     }
     $table = new object();
@@ -195,8 +188,7 @@
 
 
 if ($outcomes = grade_outcome::fetch_all_global()) {
-
-    $return = print_heading($strstandardoutcome, '', 2, 'main', true); 
+    $return = print_heading($strstandardoutcome, '', 3, 'main', true);
     $data = array();
     foreach($outcomes as $outcome) {
         $line = array();
@@ -250,6 +242,11 @@
     $outcomes_tables[] = $return;
 }
 
+if ($courseid) {
+    /// Print header
+    print_grade_page_head($courseid, 'outcome', 'edit', $heading);
+}
+
 foreach($outcomes_tables as $table) {
     print($table);
 }
Index: grade/edit/scale/edit.php
=========================================================
--- grade/edit/scale/edit.php	(revision 1.6.2.1)
+++ grade/edit/scale/edit.php	Mon Feb 09 08:35:59 CET 2009
@@ -32,9 +32,12 @@
 $id       = optional_param('id', 0, PARAM_INT);
 
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+$heading = '';
 
 // a bit complex access control :-O
 if ($id) {
+    $heading = get_string('editscale', 'grades');
+
     /// editing existing scale
     if (!$scale_rec = get_record('scale', 'id', $id)) {
         error('Incorrect scale id');
@@ -61,6 +64,7 @@
     }
 
 } else if ($courseid){
+    $heading = get_string('addscale', 'grades');
     /// adding new scale from course
     if (!$course = get_record('course', 'id', $courseid)) {
         print_error('nocourseid');
@@ -112,21 +116,15 @@
         }
         $scale->update();
     }
-
     redirect($returnurl);
 }
 
-$strgrades       = get_string('grades');
-$strgraderreport = get_string('graderreport', 'grades');
-$strscaleedit    = get_string('scale');
-
 if ($courseid) {
-    $navigation = grade_build_nav(__FILE__, $strscaleedit, $courseid);
-    print_header_simple($strgrades.': '.$strgraderreport, ': '.$strscaleedit, $navigation, '', '', true, '', navmenu($course));
+    print_grade_page_head($course->id, 'scale', 'edit', $heading);
 
 } else {
     require_once $CFG->libdir.'/adminlib.php';
-    admin_externalpage_setup('outcomes');
+    admin_externalpage_setup('scales');
     admin_externalpage_print_header();
 }
 
Index: grade/edit/scale/index.php
=========================================================
--- grade/edit/scale/index.php	(revision 1.6)
+++ grade/edit/scale/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -47,12 +47,6 @@
 /// return tracking object
 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
 
-
-$strgrades = get_string('grades');
-$pagename  = get_string('scales');
-
-$navigation = grade_build_nav(__FILE__, $pagename, array('courseid' => $courseid));
-
 $strscale          = get_string('scale');
 $strstandardscale  = get_string('scalesstandard');
 $strcustomscales   = get_string('scalescustom');
@@ -88,18 +82,17 @@
         break;
 }
 
-if ($courseid) {
-    /// Print header
-    print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
-    /// Print the plugin selector at the top
-    print_grade_plugin_selector($courseid, 'edit', 'scale');
-
-} else {
+if (!$courseid) {
     admin_externalpage_print_header();
 }
 
+$table = null;
+$table2 = null;
+$heading = '';
+
 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
-    print_heading($strcustomscales);
+    $heading = $strcustomscales;
+
     $data = array();
     foreach($scales as $scale) {
         $line = array();
@@ -123,11 +116,11 @@
     $table->align = array('left', 'center', 'center');
     $table->width = '90%';
     $table->data  = $data;
-    print_table($table);
 }
 
 if ($scales = grade_scale::fetch_all_global()) {
-    print_heading($strstandardscale);
+    $heading = $strstandardscale;
+
     $data = array();
     foreach($scales as $scale) {
         $line = array();
@@ -148,14 +141,22 @@
         $line[] = $buttons;
         $data[] = $line;
     }
-    $table->head  = array($strscale, $strused, $stredit);
-    $table->size  = array('70%', '20%', '10%');
-    $table->align = array('left', 'center', 'center');
-    $table->width = '90%';
-    $table->data  = $data;
-    print_table($table);
+    $table2->head  = array($strscale, $strused, $stredit);
+    $table2->size  = array('70%', '20%', '10%');
+    $table2->align = array('left', 'center', 'center');
+    $table2->width = '90%';
+    $table2->data  = $data;
 }
 
+
+if ($courseid) {
+    print_grade_page_head($courseid, 'scale', null, get_string('coursescales', 'grades'));
+}
+
+print_heading($strcustomscales, '', 3, 'main');
+print_table($table);
+print_heading($strstandardscale, '', 3, 'main');
+print_table($table2);
 echo '<div class="buttons">';
 print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
 echo '</div>';
Index: grade/edit/tree/category.php
=========================================================
--- grade/edit/tree/category.php	(revision 1.4.2.6)
+++ grade/edit/tree/category.php	Mon Feb 09 09:32:40 CET 2009
@@ -45,6 +45,7 @@
 
 
 $mform = new edit_category_form(null, array('gpr'=>$gpr));
+$heading = get_string('categoryedit', 'grades');
 
 if ($id) {
     if (!$grade_category = grade_category::fetch(array('id'=>$id, 'courseid'=>$course->id))) {
@@ -61,6 +62,7 @@
     $category->parentcategory = $grade_category->parent;
 
 } else {
+    $heading = get_string('newcategory', 'grades');
     $grade_category = new grade_category(array('courseid'=>$courseid), false);
     $grade_category->apply_default_settings();
     $grade_category->apply_forced_settings();
@@ -119,14 +121,7 @@
 }
 
 
-$strgrades         = get_string('grades');
-$strgraderreport   = get_string('graderreport', 'grades');
-$strcategoriesedit = get_string('categoryedit', 'grades');
-$strcategory       = get_string('category', 'grades');
-
-$navigation = grade_build_nav(__FILE__, $strcategory, array('courseid' => $courseid));
-
-print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
+print_grade_page_head($courseid, 'edittree', null, $heading);
 
 $mform->display();
 
Index: grade/edit/tree/index.php
=========================================================
--- grade/edit/tree/index.php	(revision 1.12.2.5)
+++ grade/edit/tree/index.php	Mon Feb 09 08:46:32 CET 2009
@@ -1,4 +1,4 @@
-<?php  // $Id: index.php,v 1.12.2.5 2008/02/17 19:11:29 skodak Exp $
+<?php  // $Id: index.php,v 1.4 2008/11/20 15:38:38 nicolasconnault Exp $
 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
@@ -27,13 +27,14 @@
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences
 
-$courseid = required_param('id', PARAM_INT);
-$action   = optional_param('action', 0, PARAM_ALPHA);
-$eid      = optional_param('eid', 0, PARAM_ALPHANUM);
+$courseid        = required_param('id', PARAM_INT);
+$action          = optional_param('action', 0, PARAM_ALPHA);
+$eid             = optional_param('eid', 0, PARAM_ALPHANUM);
-
+$category        = optional_param('category', null, PARAM_INT);
+$aggregationtype = optional_param('aggregationtype', null, PARAM_INT);
+$showadvanced    = optional_param('showadvanced', -1, PARAM_BOOL); // sticky editting mode
 
 /// Make sure they can even access this course
-
 if (!$course = get_record('course', 'id', $courseid)) {
     print_error('nocourseid');
 }
@@ -46,6 +47,51 @@
 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid));
 $returnurl = $gpr->get_return_url(null);
 
+/// Build editing on/off buttons
+if (!isset($USER->gradeediting)) {
+    $USER->gradeediting = array();
+}
+
+$current_view = '';
+
+if (has_capability('moodle/grade:manage', $context)) {
+    if (!isset($USER->gradeediting[$course->id])) {
+        $USER->gradeediting[$course->id] = 0;
+    }
+
+    if (($showadvanced == 1) and confirm_sesskey()) {
+        $USER->gradeediting[$course->id] = 1;
+    } else if (($showadvanced == 0) and confirm_sesskey()) {
+        $USER->gradeediting[$course->id] = 0;
+    }
+
+    // page params for the turn editting on
+    $options = $gpr->get_options();
+    $options['sesskey'] = sesskey();
+
+    if ($USER->gradeediting[$course->id]) {
+        $options['showadvanced'] = 0;
+        $current_view = 'fullview';
+    } else {
+        $options['showadvanced'] = 1;
+        $current_view = 'simpleview';
+    }
+
+} else {
+    $USER->gradeediting[$course->id] = 0;
+    $buttons = '';
+}
+
+// Change category aggregation if requested
+if (!is_null($category) && !is_null($aggregationtype)) {
+    if (!$grade_category = grade_category::fetch(array('id'=>$category, 'courseid'=>$courseid))) {
+        error('Incorrect category id!');
+    }
+    $data->aggregation = $aggregationtype;
+    grade_category::set_properties($grade_category, $data);
+    $grade_category->update();
+}
+
 //first make sure we have proper final grades - we need it for locking changes
 grade_regrade_final_grades($courseid);
 
@@ -59,7 +105,7 @@
 
 } else {
     if (!$element = $gtree->locate_element($eid)) {
-        error('Incorrect element id!', $returnurl);
+        print_error('invalidelementid', '', $returnurl);
     }
     $object = $element['object'];
 }
@@ -89,7 +135,7 @@
                 redirect($returnurl);
 
             } else {
-                print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
+                print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, null, navmenu($course));
                 $strdeletecheckfull = get_string('deletecheck', '', $object->get_name());
                 $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id, 'action'=>'delete');
                 $optionsno  = array('id'=>$course->id);
@@ -111,14 +157,22 @@
     case 'move':
         if ($eid and confirm_sesskey()) {
             $moveafter = required_param('moveafter', PARAM_ALPHANUM);
+            $first = optional_param('first', false,  PARAM_BOOL); // If First is set to 1, it means the target is the first child of the category $moveafter
+
             if(!$after_el = $gtree->locate_element($moveafter)) {
-                error('Incorect element id in moveafter', $returnurl);
+                print_error('invalidelementid', '', $returnurl);
             }
+
             $after = $after_el['object'];
-            $parent = $after->get_parent_category();
             $sortorder = $after->get_sortorder();
 
+            if (!$first) {
+                $parent = $after->get_parent_category();
-            $object->set_parent($parent->id);
+                $object->set_parent($parent->id);
+            } else {
+                $object->set_parent($after->id);
+            }
+
             $object->move_after_sortorder($sortorder);
 
             redirect($returnurl);
@@ -135,13 +189,8 @@
         break;
 }
 
-print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
 
-/// Print the plugin selector at the top
-print_grade_plugin_selector($courseid, 'edit', 'tree');
-
-print_heading(get_string('categoriesedit', 'grades'));
-
+print_grade_page_head($courseid, 'edittree', null, get_string('categoriesedit', 'grades'));
 
 print_box_start('gradetreebox generalbox');
 echo '<ul id="grade_tree">';
@@ -258,7 +307,7 @@
     }
 
     $grade_item = $element['object'];
-    
+
     if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) {
         return true;
     }
@@ -272,4 +321,5 @@
     return false;
 }
 
+
 ?>
Index: grade/edit/tree/item.php
=========================================================
--- grade/edit/tree/item.php	(revision 1.14.2.4)
+++ grade/edit/tree/item.php	Mon Feb 09 09:29:44 CET 2009
@@ -49,6 +49,8 @@
     redirect($returnurl);
 }
 
+$heading = get_string('itemsedit', 'grades');
+
 if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
     // redirect if outcomeid present
     if (!empty($grade_item->outcomeid) && !empty($CFG->enableoutcomes)) {
@@ -69,6 +71,7 @@
         $item->parentcategory = $parent_category->id;
     }
 } else {
+    $heading = get_string('newitem', 'grades');
     $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
     $item = $grade_item->get_record_data();
     $parent_category = grade_category::fetch_course_category($courseid);
@@ -159,15 +162,7 @@
     redirect($returnurl);
 }
 
-$strgrades       = get_string('grades');
-$strgraderreport = get_string('graderreport', 'grades');
-$stritemsedit    = get_string('itemsedit', 'grades');
-$stritem         = get_string('item', 'grades');
-
-$navigation = grade_build_nav(__FILE__, $stritem, array('courseid' => $courseid));
-
-
-print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stritemsedit, $navigation, '', '', true, '', navmenu($course));
+print_grade_page_head($courseid, 'edittree', null, $heading);
 
 $mform->display();
 
Index: grade/edit/tree/outcomeitem.php
=========================================================
--- grade/edit/tree/outcomeitem.php	(revision 1.15.2.7)
+++ grade/edit/tree/outcomeitem.php	Mon Feb 09 09:33:54 CET 2009
@@ -50,6 +50,8 @@
     redirect($returnurl);
 }
 
+$heading = get_string('outcomeitemsedit', 'grades');
+
 if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
     // redirect if outcomeid present
     if (empty($grade_item->outcomeid)) {
@@ -69,6 +71,7 @@
     }
 
 } else {
+    $heading = get_string('newoutcomeitem', 'grades');
     $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
     $item = $grade_item->get_record_data();
     $item->cmid = 0;
@@ -205,14 +208,7 @@
     redirect($returnurl);
 }
 
-$strgrades       = get_string('grades');
-$strgraderreport = get_string('graderreport', 'grades');
-$stroutcomesedit = get_string('outcomeitemsedit', 'grades');
-$stroutcome      = get_string('outcomeitem', 'grades');
-
-$navigation = grade_build_nav(__FILE__, $stroutcome, array('courseid' => $courseid));
-
-print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stroutcomesedit, $navigation, '', '', true, '', navmenu($course));
+print_grade_page_head($courseid, 'edittree', null, $heading);
 
 if (!grade_outcome::fetch_all_available($COURSE->id)) {
     notice_yesno(get_string('nooutcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$courseid, $returnurl);
Index: grade/export/ods/index.php
=========================================================
--- grade/export/ods/index.php	(revision 1.27.2.1)
+++ grade/export/ods/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -39,13 +39,7 @@
 require_capability('moodle/grade:export', $context);
 require_capability('gradeexport/ods:view', $context);
 
-
-$strgrades = get_string('grades', 'grades');
-$actionstr = get_string('modulename', 'gradeexport_ods');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
-
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'export', 'ods');
+print_grade_page_head($COURSE->id, 'export', 'ods', get_string('exportto', 'grades') . ' ' . get_string('modulename', 'gradeexport_ods'));
 
 if (!empty($CFG->gradepublishing)) {
     $CFG->gradepublishing = has_capability('gradeexport/ods:publish', $context);
Index: grade/export/txt/index.php
=========================================================
--- grade/export/txt/index.php	(revision 1.31.2.1)
+++ grade/export/txt/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -39,13 +39,7 @@
 require_capability('moodle/grade:export', $context);
 require_capability('gradeexport/txt:view', $context);
 
-
-$strgrades = get_string('grades', 'grades');
-$actionstr = get_string('modulename', 'gradeexport_txt');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
-
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'export', 'txt');
+print_grade_page_head($COURSE->id, 'export', 'txt', get_string('exportto', 'grades') . ' ' . get_string('modulename', 'gradeexport_txt'));
 
 if (!empty($CFG->gradepublishing)) {
     $CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context);
Index: grade/export/xls/index.php
=========================================================
--- grade/export/xls/index.php	(revision 1.26.2.1)
+++ grade/export/xls/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -39,13 +39,7 @@
 require_capability('moodle/grade:export', $context);
 require_capability('gradeexport/xls:view', $context);
 
-
-$strgrades = get_string('grades', 'grades');
-$actionstr = get_string('modulename', 'gradeexport_xls');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
-
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'export', 'xls');
+print_grade_page_head($COURSE->id, 'export', 'xls', get_string('exportto', 'grades') . ' ' . get_string('modulename', 'gradeexport_xls'));
 
 if (!empty($CFG->gradepublishing)) {
     $CFG->gradepublishing = has_capability('gradeexport/xls:publish', $context);
Index: grade/export/xml/index.php
=========================================================
--- grade/export/xml/index.php	(revision 1.35.2.2)
+++ grade/export/xml/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -39,13 +39,7 @@
 require_capability('moodle/grade:export', $context);
 require_capability('gradeexport/xml:view', $context);
 
-
-$strgrades = get_string('grades', 'grades');
-$actionstr = get_string('modulename', 'gradeexport_xml');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
-
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'export', 'xml');
+print_grade_page_head($COURSE->id, 'export', 'xml', get_string('exportto', 'grades') . ' ' . get_string('modulename', 'gradeexport_xml'));
 
 if (!empty($CFG->gradepublishing)) {
     $CFG->gradepublishing = has_capability('gradeexport/xml:publish', $context);
Index: grade/import/csv/index.php
=========================================================
--- grade/import/csv/index.php	(revision 1.31.2.4)
+++ grade/import/csv/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -59,12 +59,7 @@
     $csv_encode = '/\&\#44/';
 }
 
-$strgrades = get_string('grades', 'grades');
-$actionstr = get_string('csv', 'grades');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
-
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'import', 'csv');
+print_grade_page_head($course->id, 'import', 'csv', get_string('importcsv', 'grades'));
 
 // set up import form
 $mform = new grade_import_form(null, array('includeseparator'=>!isset($CFG->CSV_DELIMITER), 'verbosescales'=>true));
@@ -158,7 +153,7 @@
     $mform2->display();
 
 //} else if (($formdata = data_submitted()) && !empty($formdata->map)) {
- 
+
 // else if grade import mapping form is submitted
 } else if ($formdata = $mform2->get_data()) {
 
@@ -379,7 +374,7 @@
                                 } else {
                                     $scale = $gradeitem->load_scale();
                                     $scales = explode(',', $scale->scale);
-                                    $scales = array_map('trim', $scales); //hack - trim whitespace around scale options 
+                                    $scales = array_map('trim', $scales); //hack - trim whitespace around scale options
                                     array_unshift($scales, '-'); // scales start at key 1
                                     $key = array_search($value, $scales);
                                     if ($key === false) {
@@ -396,7 +391,7 @@
                             } else {
                                 if ($value === '' or $value == '-') {
                                     $value = null; // no grade
-    
+
                                 } else if (!is_numeric($value)) {
                                 // non numeric grade value supplied, possibly mapped wrong column
                                     echo "<br/>t0 is $t0";
Index: grade/import/xml/index.php
=========================================================
--- grade/import/xml/index.php	(revision 1.21)
+++ grade/import/xml/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -41,7 +41,6 @@
 // print header
 $strgrades = get_string('grades', 'grades');
 $actionstr = get_string('modulename', 'gradeimport_xml');
-$navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course->id));
 
 if (!empty($CFG->gradepublishing)) {
     $CFG->gradepublishing = has_capability('gradeimport/xml:publish', $context);
@@ -60,8 +59,8 @@
     }
 
     if ($text = $mform->get_file_content('userfile')) {
-        print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-        print_grade_plugin_selector($id, 'import', 'xml');
+
+        print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
 
         $error = '';
         $importcode = import_xml_grades($text, $course, $error);
@@ -84,8 +83,7 @@
             $data->key = create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
         }
 
-        print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-        print_grade_plugin_selector($id, 'import', 'xml');
+        print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
 
         echo '<div class="gradeexportlink">';
         $link = $CFG->wwwroot.'/grade/import/xml/fetch.php?id='.$id.'&amp;feedback='.(int)($data->feedback).'&amp;url='.urlencode($data->url).'&amp;key='.$data->key;
@@ -96,8 +94,7 @@
     }
 }
 
-print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation);
-print_grade_plugin_selector($id, 'import', 'xml');
+print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));
 
 $mform->display();
 
Index: grade/lib.php
=========================================================
--- grade/lib.php	(revision 1.120.2.22)
+++ grade/lib.php	Mon Feb 09 08:49:07 CET 2009
@@ -301,14 +301,132 @@
  * @param boolean $return return as string
  * @return nothing or string if $return true
  */
-function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $return=false) {
+function print_grade_plugin_selector($plugin_info, $return=false) {
+    global $CFG;
+
+    $menu = array();
+    $count = 0;
+    $active = '';
+
+    foreach ($plugin_info as $plugin_type => $plugins) {
+        if ($plugin_type == 'strings') {
+            continue;
+        }
+
+        $menu[$plugin_type.'group'] = '--'.$plugin_info['strings'][$plugin_type];
+
+        if (!empty($plugins['id'])) {
+            $menu[$plugins['link']] = $plugins['string'];
+        } else {
+            foreach ($plugins as $plugin) {
+                $menu[$plugin['link']] = $plugin['string'];
+                $count++;
+            }
+        }
+    }
+
+/// finally print/return the popup form
+    if ($count > 1) {
+        return popup_form('', $menu, 'choosepluginreport', '', get_string('chooseaction', 'grades'), '', '', $return, 'self');
+    } else {
+        // only one option - no plugin selector needed
+        return '';
+    }
+}
+
+/**
+ * Print grading plugin selection tab-based navigation.
+ *
+ * @param int $courseid id of course
+ * @param string $active_type type of plugin on current page - import, export, report or edit
+ * @param string $active_plugin active plugin type - grader, user, cvs, ...
+ * @param boolean $return return as string
+ * @param string $preferences_page_url Unless false, the link to a preferences page to print in the second row of tabs next to the current link. If true, we are ON the preferences page
+ * @return nothing or string if $return true
+ */
+function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=false, $preferences_page_url=false) {
+    global $CFG, $COURSE;
+
+    if (!isset($currenttab)) {
+        $currenttab = '';
+    }
+
+    $tabs = array();
+    $top_row  = array();
+    $bottom_row = array();
+    $inactive = array($active_plugin);
+    $activated = array();
+
+    $count = 0;
+    $active = '';
+
+    foreach ($plugin_info as $plugin_type => $plugins) {
+        if ($plugin_type == 'strings') {
+            continue;
+        }
+
+        // If $plugins is actually the definition of a child-less parent link:
+        if (!empty($plugins['id'])) {
+            $top_row[] = new tabobject($plugin_type, $plugins['link'], $plugins['string']);
+            continue;
+        }
+
+        $first_plugin = reset($plugins);
+        $url = $first_plugin['link'];
+
+        if ($plugin_type == 'report') {
+            $url = $CFG->wwwroot.'/grade/report/index.php?id='.$COURSE->id;
+        }
+
+        $top_row[] = new tabobject($plugin_type, $url, $plugin_info['strings'][$plugin_type]);
+
+        if ($active_type == $plugin_type) {
+            foreach ($plugins as $plugin) {
+                $bottom_row[] = new tabobject($plugin['id'], $plugin['link'], $plugin['string']);
+                if ($plugin['id'] == $active_plugin) {
+                    $inactive = array($plugin['id']);
+
+                    // Add preferences link if setup
+                    if ($preferences_page_url) {
+                        $bottom_row[] = new tabobject('preferences', $preferences_page_url, get_string('preferences'));
+                        if ($preferences_page_url === true) {
+                            $inactive = array('preferences');
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    $tabs[] = $top_row;
+    $tabs[] = $bottom_row;
+
+    if ($return) {
+        return print_tabs($tabs, $active_type, $inactive, $activated, true);
+    } else {
+        print_tabs($tabs, $active_type, $inactive, $activated);
+    }
+}
+
+function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
     global $CFG;
 
     $context = get_context_instance(CONTEXT_COURSE, $courseid);
 
-    $menu = array();
+    $plugin_info = array();
     $count = 0;
     $active = '';
+    $url_prefix = $CFG->wwwroot . '/grade/';
+
+    // Language strings
+    $plugin_info['strings'] = array(
+        'report' => get_string('view'),
+        'edittree' => get_string('edittree', 'grades'),
+        'scale' => get_string('scales'),
+        'outcome' => get_string('outcomes', 'grades'),
+        'letter' => get_string('letters', 'grades'),
+        'export' => get_string('export', 'grades'),
+        'import' => get_string('import'));
 
 /// report plugins with its special structure
     if ($reports = get_list_of_plugins('grade/report', 'CVS')) {         // Get all installed reports
@@ -321,20 +439,102 @@
     $reportnames = array();
     if (!empty($reports)) {
         foreach ($reports as $plugin) {
-            $url = 'report/'.$plugin.'/index.php?id='.$courseid;
+            $url = $url_prefix.'report/'.$plugin.'/index.php?id='.$courseid;
             if ($active_type == 'report' and $active_plugin == $plugin ) {
                 $active = $url;
             }
-            $reportnames[$url] = get_string('modulename', 'gradereport_'.$plugin);
+            $reportnames[$plugin] = array('id' => $plugin, 'link' => $url, 'string' => get_string('modulename', 'gradereport_'.$plugin));
             $count++;
         }
         asort($reportnames);
     }
     if (!empty($reportnames)) {
-        $menu['reportgroup']='--'.get_string('view');
-        $menu = $menu+$reportnames;
+        $plugin_info['report']=$reportnames;
+    }
+
+/// editing scripts - not real plugins
+    if (has_capability('moodle/grade:manage', $context)
+      or has_capability('moodle/grade:manageletters', $context)
+      or has_capability('moodle/course:managescales', $context)
+      or has_capability('moodle/course:update', $context)) {
+
+        if (has_capability('moodle/grade:manage', $context)) {
+            $url = $url_prefix.'edit/tree/index.php?sesskey='.sesskey().'&amp;id='.$courseid;
+
+            if ($active_type == 'edittree' and is_null($active_plugin)) {
+                $active = $url;
+            }
+
+            $plugin_info['edittree'] = array('id' => 'edittree', 'link' => $url, 'string' => get_string('edittree', 'grades'));
+            $count++;
+        }
+
+        if (has_capability('moodle/course:managescales', $context)) {
+            $url = $url_prefix.'edit/scale/index.php?id='.$courseid;
+            if ($active_type == 'scale' and is_null($active_plugin)) {
+                $active = $url;
+            }
+            $plugin_info['scale'] = array('id' => 'scale', 'link' => $url, 'string' => get_string('scales'));
+            $count++;
+        }
+
+        if (!empty($CFG->enableoutcomes) && (has_capability('moodle/grade:manage', $context) or
+                                             has_capability('moodle/course:update', $context))) {
+
+            $url_course = $url_prefix.'edit/outcome/course.php?id='.$courseid;
+            $url_edit = $url_prefix.'edit/outcome/index.php?id='.$courseid;
+
+            $plugin_info['outcome'] = array();
+
+            if (has_capability('moodle/course:update', $context)) {  // Default to course assignment
+                $plugin_info['outcome']['course'] = array('id' => 'course', 'link' => $url_course, 'string' => get_string('outcomescourse', 'grades'));
+                $plugin_info['outcome']['edit'] = array('id' => 'edit', 'link' => $url_edit, 'string' => get_string('editoutcomes', 'grades'));
+            } else {
+                $plugin_info['outcome'] = array('id' => 'edit', 'link' => $url_course, 'string' => get_string('outcomescourse', 'grades'));
+            }
+
+            if ($active_type == 'outcome' and is_null($active_plugin)) {
+                $active = $url_edit;
+            } elseif ($active_type == 'outcome' and $active_plugin == 'course' ) {
+                $active = $url_course;
+            } elseif ($active_type == 'outcome' and $active_plugin == 'edit' ) {
+                $active = $url_edit;
+            }
+
+            $count++;
-    }
+        }
 
+        if (has_capability('moodle/grade:manage', $context) or has_capability('moodle/grade:manageletters', $context)) {
+            $course_context = get_context_instance(CONTEXT_COURSE, $courseid);
+            $url = $url_prefix.'edit/letter/index.php?id='.$courseid;
+            $url_edit = $url_prefix.'edit/letter/edit.php?id='.$course_context->id;
+
+            if ($active_type == 'letter' and $active_plugin == 'view' ) {
+                $active = $url;
+            } elseif ($active_type == 'letter' and $active_plugin == 'edit' ) {
+                $active = $url_edit;
+            }
+
+            $plugin_info['letter'] = array();
+            $plugin_info['letter']['view'] = array('id' => 'view', 'link' => $url, 'string' => get_string('view'));
+            $plugin_info['letter']['edit'] = array('id' => 'edit', 'link' => $url_edit, 'string' => get_string('edit'));
+            $count++;
+        }
+
+        /**
+         * Moving to Course settings
+         *
+        if (has_capability('moodle/grade:manage', $context)) {
+            $url = $url_prefix.'edit/settings/index.php?id='.$courseid;
+            if ($active_type == 'edit' and $active_plugin == 'settings' ) {
+                $active = $url;
+            }
+            $plugin_info['edit'][] = array('id' => $plugin, 'link' => $url, 'string' => get_string('coursesettings', 'grades'));
+            $count++;
+        }
+        */
+    }
+
 /// standard import plugins
     if ($imports = get_list_of_plugins('grade/import', 'CVS')) {         // Get all installed import plugins
         foreach ($imports as $key => $plugin) {                      // Remove ones we can't see
@@ -346,18 +546,17 @@
     $importnames = array();
     if (!empty($imports)) {
         foreach ($imports as $plugin) {
-            $url = 'import/'.$plugin.'/index.php?id='.$courseid;
+            $url = $url_prefix.'import/'.$plugin.'/index.php?id='.$courseid;
             if ($active_type == 'import' and $active_plugin == $plugin ) {
                 $active = $url;
             }
-            $importnames[$url] = get_string('modulename', 'gradeimport_'.$plugin);
+            $importnames[$plugin] = array('id' => $plugin, 'link' => $url, 'string' => get_string('modulename', 'gradeimport_'.$plugin));
             $count++;
         }
         asort($importnames);
     }
     if (!empty($importnames)) {
-        $menu['importgroup']='--'.get_string('importfrom', 'grades');
-        $menu = $menu+$importnames;
+        $plugin_info['import']=$importnames;
     }
 
 /// standard export plugins
@@ -371,86 +570,80 @@
     $exportnames = array();
     if (!empty($exports)) {
         foreach ($exports as $plugin) {
-            $url = 'export/'.$plugin.'/index.php?id='.$courseid;
+            $url = $url_prefix.'export/'.$plugin.'/index.php?id='.$courseid;
             if ($active_type == 'export' and $active_plugin == $plugin ) {
                 $active = $url;
             }
-            $exportnames[$url] = get_string('modulename', 'gradeexport_'.$plugin);
+            $exportnames[$plugin] = array('id' => $plugin, 'link' => $url, 'string' => get_string('modulename', 'gradeexport_'.$plugin));
             $count++;
         }
         asort($exportnames);
     }
+
     if (!empty($exportnames)) {
-        $menu['exportgroup']='--'.get_string('exportto', 'grades');
-        $menu = $menu+$exportnames;
+        $plugin_info['export']=$exportnames;
     }
 
-/// editing scripts - not real plugins
-    if (has_capability('moodle/grade:manage', $context)
-      or has_capability('moodle/grade:manageletters', $context)
-      or has_capability('moodle/course:managescales', $context)
-      or has_capability('moodle/course:update', $context)) {
-        $menu['edit']='--'.get_string('edit');
-
-        if (has_capability('moodle/grade:manage', $context)) {
-            $url = 'edit/tree/index.php?id='.$courseid;
-            if ($active_type == 'edit' and $active_plugin == 'tree' ) {
-                $active = $url;
+    foreach ($plugin_info as $plugin_type => $plugins) {
+        if (!empty($plugins['id']) && $active_plugin == $plugins['id']) {
+            $plugin_info['strings']['active_plugin_str'] = $plugins['string'];
+            break;
-            }
+        }
-            $menu[$url] = get_string('edittree', 'grades');
-            $count++;
+        foreach ($plugins as $plugin) {
+            if ($active_plugin == $plugin['id']) {
+                $plugin_info['strings']['active_plugin_str'] = $plugin['string'];
-        }
+            }
-
-        if (has_capability('moodle/course:managescales', $context)) {
-            $url = 'edit/scale/index.php?id='.$courseid;
-            if ($active_type == 'edit' and $active_plugin == 'scale' ) {
-                $active = $url;
-            }
+        }
-            $menu[$url] = get_string('scales');
-            $count++;
-        }
+    }
 
-        if (!empty($CFG->enableoutcomes) && (has_capability('moodle/grade:manage', $context) or
-                                             has_capability('moodle/course:update', $context))) {
-            if (has_capability('moodle/course:update', $context)) {  // Default to course assignment
-                $url = 'edit/outcome/course.php?id='.$courseid;
-            } else {
-                $url = 'edit/outcome/index.php?id='.$courseid;
-            }
-            if ($active_type == 'edit' and $active_plugin == 'outcome' ) {
-                $active = $url;
-            }
-            $menu[$url] = get_string('outcomes', 'grades');
-            $count++;
-        }
+    return $plugin_info;
+}
 
-        if (has_capability('moodle/grade:manage', $context) or has_capability('moodle/grade:manageletters', $context)) {
-            $url = 'edit/letter/index.php?id='.$courseid;
-            if ($active_type == 'edit' and $active_plugin == 'letter' ) {
-                $active = $url;
-            }
-            $menu[$url] = get_string('letters', 'grades');
-            $count++;
-        }
+function print_grade_page_head($courseid, $active_type, $active_plugin=null, $heading = false, $return=false, $meta='', $preferences_page_url=false, $buttons=false) {
+    global $CFG, $COURSE;
+    $strgrades = get_string('grades');
+    $plugin_info = grade_get_plugin_info($courseid, $active_type, $active_plugin);
 
-        if (has_capability('moodle/grade:manage', $context)) {
-            $url = 'edit/settings/index.php?id='.$courseid;
-            if ($active_type == 'edit' and $active_plugin == 'settings' ) {
-                $active = $url;
+    // Determine the string of the active plugin
+    $stractive_plugin = ($active_plugin) ? $plugin_info['strings']['active_plugin_str'] : $heading;
+    $stractive_type = $plugin_info['strings'][$active_type];
+
+    $navlinks = array();
+    $navlinks[] = array('name' => $strgrades,
+                        'link' => $CFG->wwwroot.'/grade/index.php?id='.$COURSE->id,
+                        'type' => 'misc');
+
+    $active_type_link = '';
+
+    if (!empty($plugin_info[$active_type]['link'])) {
+        $active_type_link = $plugin_info[$active_type]['link'];
-            }
+    }
-            $menu[$url] = get_string('coursesettings', 'grades');
-            $count++;
+
+    $navlinks[] = array('name' => $stractive_type, 'link' => $active_type_link, 'type' => 'misc');
+
+    if ($preferences_page_url === true) {
+        $navlinks[] = array('name' => $stractive_plugin, 'link' => $plugin_info[$active_type][$active_plugin]['link'], 'type' => 'misc');
+        $navlinks[] = array('name' => get_string('preferences'), 'link' => null, 'type' => 'misc');
+    } else {
+        $navlinks[] = array('name' => $stractive_plugin, 'link' => null, 'type' => 'misc');
-        }
+    }
 
+    $navigation = build_navigation($navlinks);
+
+    $returnval = print_header_simple($strgrades . ': ' . $stractive_type, ': ' . $stractive_type . ': ' . $stractive_plugin, $navigation, '',
+            $meta, true, $buttons, navmenu($COURSE), false, '', $return);
+
+    // Guess heading if not given explicitly
+    if (!$heading) {
+        $heading = $stractive_plugin;
     }
 
-/// finally print/return the popup form
-    if ($count > 1) {
-        return popup_form($CFG->wwwroot.'/grade/', $menu, 'choosepluginreport', '',
-                get_string('chooseaction', 'grades'), '', '', $return, 'self');
-    } else {
-        // only one option - no plugin selector needed
-        return '';
+    $returnval .= print_grade_plugin_selector($plugin_info, $return);
+    $returnval .= print_heading($heading);
+    $returnval .= grade_print_tabs($active_type, $active_plugin, $plugin_info, $return, $preferences_page_url);
+
+    if ($return) {
+        return $returnval;
     }
 }
 
@@ -783,7 +976,8 @@
             case 'courseitem':
             case 'categoryitem':
                 if ($element['object']->is_calculated()) {
-                    return '<img src="'.$CFG->pixpath.'/i/calc.gif" class="icon itemicon" alt="'.get_string('calculation', 'grades').'"/>';
+                    $strcalc = get_string('calculatedgrade', 'grades');
+                    return '<img src="'.$CFG->pixpath.'/i/calc.gif" class="icon itemicon" title="'.$strcalc.'" alt="'.$strcalc.'"/>';
 
                 } else if (($element['object']->is_course_item() or $element['object']->is_category_item())
                   and ($element['object']->gradetype == GRADE_TYPE_SCALE or $element['object']->gradetype == GRADE_TYPE_VALUE)) {
@@ -794,27 +988,32 @@
                             case GRADE_AGGREGATE_WEIGHTED_MEAN:
                             case GRADE_AGGREGATE_WEIGHTED_MEAN2:
                             case GRADE_AGGREGATE_EXTRACREDIT_MEAN:
-                                return '<img src="'.$CFG->pixpath.'/i/agg_mean.gif" class="icon itemicon" alt="'.get_string('aggregation', 'grades').'"/>';
+                                $stragg = get_string('aggregation', 'grades');
+                                return '<img src="'.$CFG->pixpath.'/i/agg_mean.gif" class="icon itemicon" title="'.$stragg.'" alt="'.$stragg.'"/>';
                             case GRADE_AGGREGATE_SUM:
-                                return '<img src="'.$CFG->pixpath.'/i/agg_sum.gif" class="icon itemicon" alt="'.get_string('aggregation', 'grades').'"/>';
+                                $stragg = get_string('aggregation', 'grades');
+                                return '<img src="'.$CFG->pixpath.'/i/agg_sum.gif" class="icon itemicon" title="'.$stragg.'" alt="'.$stragg.'"/>';
                         }
                     }
 
                 } else if ($element['object']->itemtype == 'mod') {
-                    return '<img src="'.$CFG->modpixpath.'/'.$element['object']->itemmodule.'/icon.gif" class="icon itemicon" alt="'
-                           .get_string('modulename', $element['object']->itemmodule).'"/>';
+                    $strmodname = get_string('modulename', $element['object']->itemmodule);
+                    return '<img src="'.$CFG->modpixpath.'/'.$element['object']->itemmodule.'/icon.gif" class="icon itemicon" title="' .$strmodname.'" alt="' .$strmodname.'"/>';
 
                 } else if ($element['object']->itemtype == 'manual') {
                     if ($element['object']->is_outcome_item()) {
-                        return '<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon itemicon" alt="'.get_string('outcome', 'grades').'"/>';
+                        $stroutcome = get_string('outcome', 'grades');
+                        return '<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon itemicon" title="'.$stroutcome.'" alt="'.$stroutcome.'"/>';
                     } else {
-                        return '<img src="'.$CFG->pixpath.'/t/manual_item.gif" class="icon itemicon" alt="'.get_string('manualitem', 'grades').'"/>';
+                        $strmanual = get_string('manualitem', 'grades');
+                        return '<img src="'.$CFG->pixpath.'/t/manual_item.gif" class="icon itemicon" title="'.$strmanual.'" alt="'.$strmanual.'"/>';
                     }
                 }
                 break;
 
             case 'category':
-                return '<img src="'.$CFG->pixpath.'/f/folder.gif" class="icon itemicon" alt="'.get_string('category', 'grades').'"/>';
+                $strcat = get_string('category', 'grades');
+                return '<img src="'.$CFG->pixpath.'/f/folder.gif" class="icon itemicon" title="'.$strcat.'" alt="'.$strcat.'" />';
         }
 
         if ($spacerifnone) {
@@ -841,8 +1040,7 @@
             $header .= $this->get_element_icon($element, $spacerifnone);
         }
 
-        $title = $element['object']->get_name();
-        $header .= $title;
+        $header .= $element['object']->get_name();
 
         if ($element['type'] != 'item' and $element['type'] != 'categoryitem' and $element['type'] != 'courseitem') {
             return $header;
@@ -855,6 +1053,8 @@
         if ($withlink and $itemtype=='mod' and $iteminstance and $itemmodule) {
             if ($cm = get_coursemodule_from_instance($itemmodule, $iteminstance, $this->courseid)) {
 
+                $a->name = get_string('modulename', $element['object']->itemmodule);
+                $title = get_string('linktoactivity', 'grades', $a);
                 $dir = $CFG->dirroot.'/mod/'.$itemmodule;
 
                 if (file_exists($dir.'/grade.php')) {
Index: grade/report/grader/index.php
=========================================================
--- grade/report/grader/index.php	(revision 1.65.2.9)
+++ grade/report/grader/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -60,13 +60,6 @@
 }
 $USER->grade_last_report[$course->id] = 'grader';
 
-/// Build navigation
-
-$strgrades  = get_string('grades');
-$reportname = get_string('modulename', 'gradereport_grader');
-
-$navigation = grade_build_nav(__FILE__, $reportname, $courseid);
-
 /// Build editing on/off buttons
 
 if (!isset($USER->gradeediting)) {
@@ -141,19 +134,18 @@
 $report->load_final_grades();
 
 /// Print header
-print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
-                        '', '', true, $buttons, navmenu($course));
+$meta = '<!--[if IE]><link rel="stylesheet" type="text/css" href="styles_ie.css" />'.
+             '<![endif]--><!--[if IE 6]><link rel="stylesheet" type="text/css" href="styles_ie6.css"'.
+             '/><![endif]-->';
 
-/// Print the plugin selector at the top
-print_grade_plugin_selector($courseid, 'report', 'grader');
 
-// Add tabs
-$currenttab = 'graderreport';
-require('tabs.php');
+$reportname = get_string('modulename', 'gradereport_grader');
+
+print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $meta, $report->preferences_page, $buttons);
 
 echo $report->group_selector;
 echo '<div class="clearer"></div>';
-echo $report->get_toggles_html();
+// echo $report->get_toggles_html();
 
 //show warnings if any
 foreach($warnings as $warning) {
@@ -167,15 +159,15 @@
 }
 
 $reporthtml = '<script src="functions.js" type="text/javascript"></script>';
-
-$reporthtml .= '<table id="user-grades" class="gradestable flexible boxaligncenter generaltable">';
+$reporthtml .= '<div class="gradeparent">';
+$reporthtml .= $report->get_studentnameshtml();
 $reporthtml .= $report->get_headerhtml();
 $reporthtml .= $report->get_iconshtml();
+$reporthtml .= $report->get_studentshtml();
 $reporthtml .= $report->get_rangehtml();
-$reporthtml .= $report->get_studentshtml();
 $reporthtml .= $report->get_avghtml(true);
 $reporthtml .= $report->get_avghtml();
-$reporthtml .= "</table>";
+$reporthtml .= "</tbody></table></div></div>";
 
 // print submit button
 if ($USER->gradeediting[$course->id]) {
Index: grade/report/grader/lib.php
=========================================================
--- grade/report/grader/lib.php	(revision 1.98.2.49)
+++ grade/report/grader/lib.php	Mon Feb 09 08:36:56 CET 2009
@@ -85,6 +85,8 @@
      * */
     var $canviewhidden;
 
+    var $preferences_page=false;
+
     /**
      * Constructor. Sets local copies of user preferences and initialises grade_tree.
      * @param int $courseid
@@ -489,31 +491,8 @@
     function get_headerhtml() {
         global $CFG, $USER;
 
-        $strsortasc   = $this->get_lang_string('sortasc', 'grades');
-        $strsortdesc  = $this->get_lang_string('sortdesc', 'grades');
-        $strfirstname = $this->get_lang_string('firstname');
-        $strlastname  = $this->get_lang_string('lastname');
-        $showuseridnumber = $this->get_pref('showuseridnumber');
-
-        if ($this->sortitemid === 'lastname') {
-            if ($this->sortorder == 'ASC') {
-                $lastarrow = print_arrow('up', $strsortasc, true);
-            } else {
-                $lastarrow = print_arrow('down', $strsortdesc, true);
-            }
-        } else {
-            $lastarrow = '';
-        }
+        $this->rowcount = 0;
 
-        if ($this->sortitemid === 'firstname') {
-            if ($this->sortorder == 'ASC') {
-                $firstarrow = print_arrow('up', $strsortasc, true);
-            } else {
-                $firstarrow = print_arrow('down', $strsortdesc, true);
-            }
-        } else {
-            $firstarrow = '';
-        }
         // Prepare Table Headers
         $headerhtml = '';
 
@@ -521,7 +500,6 @@
 
         $columns_to_unset = array();
 
-
         foreach ($this->gtree->levels as $key=>$row) {
             $columncount = 0;
             if ($key == 0) {
@@ -529,37 +507,8 @@
                 // continue;
             }
 
-            $headerhtml .= '<tr class="heading r'.$this->rowcount++.'">';
-
-            if ($key == $numrows - 1) {
-                $headerhtml .= '<th class="header c'.$columncount++.'" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=firstname">'
-                            . $strfirstname . '</a> '
-                            . $firstarrow. '/ <a href="'.$this->baseurl.'&amp;sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>';
-                if ($showuseridnumber) {
-                    if ('idnumber' == $this->sortitemid) {
-                        if ($this->sortorder == 'ASC') {
-                            $idnumberarrow = print_arrow('up', $strsortasc, true);
-                        } else {
-                            $idnumberarrow = print_arrow('down', $strsortdesc, true);
-                        }
-                    } else {
-                        $idnumberarrow = '';
-                    }
-                    $headerhtml .= '<th class="header c'.$columncount++.' useridnumber" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=idnumber">'
-                            . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>';
-                }
-             } else {
-                $colspan='';
-                if ($showuseridnumber) {
-                    $colspan = 'colspan="2" ';
-                }
+            $headerhtml .= '<tr class="heading_name_row">';
 
-                $headerhtml .= '<td '.$colspan.'class="cell c'.$columncount++.' topleft">&nbsp;</td>';
-
-                if ($showuseridnumber) {
-                    $columncount++;
-                }
-            }
 
             foreach ($row as $columnkey => $element) {
                 $sort_link = '';
@@ -649,8 +598,6 @@
         $strfeedback  = $this->get_lang_string("feedback");
         $strgrade     = $this->get_lang_string('grade');
         $gradetabindex = 1;
-        $showuserimage = $this->get_pref('showuserimage');
-        $showuseridnumber = $this->get_pref('showuseridnumber');
         $numusers      = count($this->users);
 
         // Preload scale objects for items with a scaleid
@@ -690,21 +637,7 @@
             }
 
             $columncount = 0;
-            // Student name and link
-            $user_pic = null;
-            if ($showuserimage) {
-                $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, NULL, 0, true) . '</div>';
-            }
-
-            $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
-                          .'<th class="header c'.$columncount++.' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
-                          .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
-                          .fullname($user).'</a></th>';
-
-            if ($showuseridnumber) {
-                $studentshtml .= '<th class="header c'.$columncount++.' useridnumber" onclick="set_row(this.parentNode.rowIndex);">'.
-                        $user->idnumber.'</th>';
-            }
+            $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
 
             foreach ($this->gtree->items as $itemid=>$unused) {
                 $item =& $this->gtree->items[$itemid];
@@ -749,13 +682,13 @@
                 }
 
                 if ($grade->is_excluded()) {
-                    $cellclasses .= ' excluded';
+                    // $cellclasses .= ' excluded';
                 }
 
                 $studentshtml .= '<td class="'.$cellclasses.'">';
 
                 if ($grade->is_excluded()) {
-                    $studentshtml .= get_string('excluded', 'grades') . ' ';
+                    $studentshtml .= '<span class="excludedfloater">'.get_string('excluded', 'grades') . '</span> ';
                 }
 
                 // Do not show any icons if no grade (no record in DB to match)
@@ -839,9 +772,7 @@
 
                     // If quickfeedback is on, print an input element
                     if ($this->get_pref('showquickfeedback') and $grade->is_editable()) {
-                        if ($this->get_pref('quickgrading')) {
-                            $studentshtml .= '<br />';
-                        }
+
                         $studentshtml .= '<input type="hidden" name="oldfeedback_'
                                       .$userid.'_'.$item->id.'" value="' . s($grade->feedback) . '" />';
                         $studentshtml .= '<input class="quickfeedback" tabindex="' . $tabindices[$item->id]['feedback']
@@ -885,6 +816,133 @@
         return $studentshtml;
     }
 
+    function get_studentnameshtml() {
+        global $CFG, $USER;
+        $studentshtml = '';
+
+        $showuserimage = $this->get_pref('showuserimage');
+        $showuseridnumber = $this->get_pref('showuseridnumber');
+
+        $strsortasc   = $this->get_lang_string('sortasc', 'grades');
+        $strsortdesc  = $this->get_lang_string('sortdesc', 'grades');
+        $strfirstname = $this->get_lang_string('firstname');
+        $strlastname  = $this->get_lang_string('lastname');
+
+        if ($this->sortitemid === 'lastname') {
+            if ($this->sortorder == 'ASC') {
+                $lastarrow = print_arrow('up', $strsortasc, true);
+            } else {
+                $lastarrow = print_arrow('down', $strsortdesc, true);
+            }
+        } else {
+            $lastarrow = '';
+        }
+
+        if ($this->sortitemid === 'firstname') {
+            if ($this->sortorder == 'ASC') {
+                $firstarrow = print_arrow('up', $strsortasc, true);
+            } else {
+                $firstarrow = print_arrow('down', $strsortdesc, true);
+            }
+        } else {
+            $firstarrow = '';
+        }
+
+        $row_classes = array(' even ', ' odd ');
+
+        $row_classes = array(' even ', ' odd ');
+
+        $studentshtml .= '<div class="left_scroller">
+            <table id="fixed_column" class="fixed_grades_column">
+                <tbody class="leftbody">';
+
+        $colspan = '';
+        if ($showuseridnumber) {
+            $colspan = 'colspan="2"';
+        }
+
+        $levels = count($this->gtree->levels) - 1;
+
+
+        for ($i = 0; $i < $levels; $i++) {
+            $studentshtml .= '
+                    <tr class="heading name_row">
+                        <td '.$colspan.' class="fixedcolumn cell c0 topleft"> </td>
+                    </tr>
+                    ';
+        }
+
+        $studentshtml .= '<tr class="heading"><th class="header c0" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=firstname">'
+                    . $strfirstname . '</a> '
+                    . $firstarrow. '/ <a href="'.$this->baseurl.'&amp;sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>';
+
+        if ($showuseridnumber) {
+            if ('idnumber' == $this->sortitemid) {
+                if ($this->sortorder == 'ASC') {
+                    $idnumberarrow = print_arrow('up', $strsortasc, true);
+                } else {
+                    $idnumberarrow = print_arrow('down', $strsortdesc, true);
+                }
+            } else {
+                $idnumberarrow = '';
+            }
+            $studentshtml .= '<th class="header c0 useridnumber" scope="col"><a href="'.$this->baseurl.'&amp;sortitemid=idnumber">'
+                    . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>';
+        }
+
+        $studentshtml .= '</tr>';
+
+        if ($USER->gradeediting[$this->courseid]) {
+            $studentshtml .= '<tr class="controls"><th class="header c0 controls" scope="row" '.$colspan.'>'.$this->get_lang_string('controls','grades').'</th></tr>';
+        }
+
+        foreach ($this->users as $userid => $user) {
+
+            $user_pic = null;
+            if ($showuserimage) {
+                $user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, NULL, 0, true) . "</div>\n";
+            }
+
+            $studentshtml .= '<tr class="r'.$this->rowcount++ . $row_classes[$this->rowcount % 2] . '">'
+                          .'<th class="header c0 user" scope="row" onclick="set_row(this.parentNode.rowIndex);">'.$user_pic
+                          .'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'">'
+                          .fullname($user)."</a></th>\n";
+
+            if ($showuseridnumber) {
+                $studentshtml .= '<th class="header c0 useridnumber" onclick="set_row(this.parentNode.rowIndex);">'. $user->idnumber."</th>\n";
+            }
+            $studentshtml .= "</tr>\n";
+        }
+
+        if ($this->get_pref('showranges')) {
+            $studentshtml .= '<tr class="range r'.$this->rowcount++.'">' . '<th class="header c0 range " '.$colspan.' scope="row">'.$this->get_lang_string('range','grades').'</th></tr>';
+        }
+
+        // Averages heading
+
+        $straverage_group = get_string('groupavg', 'grades');
+        $showaverages_group = $this->currentgroup && $this->get_pref('showgroups');
+        $straverage = get_string('overallaverage', 'grades');
+        $showaverages = $this->get_pref('showaverages');
+
+        if ($showaverages_group) {
+            $studentshtml .= '<tr class="groupavg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage_group.'</th></tr>';
+        }
+
+        if ($showaverages) {
+            $studentshtml .= '<tr class="avg r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage.'</th></tr>';
+        }
+
+        $studentshtml .= '</tbody>
+            </table>
+        </div>
+        <div class="right_scroller">
+            <table id="user-grades" class="">
+                <tbody class="righttest">';
+
+        return $studentshtml;
+    }
+
     /**
      * Builds and return the HTML row of column totals.
      * @param  bool $grouponly Whether to return only group averages or all averages.
@@ -903,7 +961,6 @@
         $averagesdecimalpoints = $this->get_pref('averagesdecimalpoints');
         $meanselection         = $this->get_pref('meanselection');
         $shownumberofgrades    = $this->get_pref('shownumberofgrades');
-        $showuseridnumber      = $this->get_pref('showuseridnumber');
 
         $avghtml = '';
         $avgcssclass = 'avg';
@@ -950,16 +1007,8 @@
             }
 
             $columncount=0;
-            $colspan='';
-            if ($showuseridnumber) {
-                $colspan = 'colspan="2" ';
-            }
 
-            $avghtml = '<tr class="' . $avgcssclass . ' r'.$this->rowcount++.'"><th class="header c0" '.$colspan.'scope="row">'.$straverage.'</th>';
-
-            if ($showuseridnumber) {
-                $columncount++;
-            }
+            $avghtml = '<tr class="' . $avgcssclass . ' r'.$this->rowcount++.'">';
 
             // MDL-10875 Empty grades must be evaluated as grademin, NOT always 0
             // This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
@@ -1050,7 +1099,6 @@
      */
     function get_rangehtml() {
         global $USER;
-        $showuseridnumber      = $this->get_pref('showuseridnumber');
 
         $scalehtml = '';
         if ($this->get_pref('showranges')) {
@@ -1058,17 +1106,8 @@
             $rangesdecimalpoints = $this->get_pref('rangesdecimalpoints');
 
             $columncount=0;
-            $colspan='';
-            if ($showuseridnumber) {
-                $colspan = 'colspan="2" ';
-            }
+            $scalehtml = '<tr class="range r'.$this->rowcount++.' heading">';
 
-            $scalehtml = '<tr class="r'.$this->rowcount++.'">'
-                       . '<th class="header c0 range" '.$colspan.'scope="row">'.$this->get_lang_string('range','grades').'</th>';
-
-            if ($showuseridnumber) {
-                $columncount++;
-            }
 
             foreach ($this->gtree->items as $itemid=>$unused) {
                 $item =& $this->gtree->items[$itemid];
@@ -1099,15 +1138,9 @@
         $iconshtml = '';
         if ($USER->gradeediting[$this->courseid]) {
 
-            $colspan='';
-            if ($this->get_pref('showuseridnumber')) {
-                $colspan = 'colspan="2" ';
-            }
-
-            $iconshtml = '<tr class="r'.$this->rowcount++.'">'
-                       . '<th class="header c0 range" scope="row" '.$colspan.'>'.$this->get_lang_string('controls','grades').'</th>';
+            $iconshtml = '<tr class="controls">';
 
-            $columncount = 1;
+            $columncount = 0;
             foreach ($this->gtree->items as $itemid=>$unused) {
                 // emulate grade element
                 $item =& $this->gtree->items[$itemid];
@@ -1115,7 +1148,7 @@
                 $eid = $this->gtree->get_item_eid($item);
                 $element = $this->gtree->locate_element($eid);
 
-                $iconshtml .= '<td class="cell c'.$columncount++.' icons">' . $this->get_icons($element) . '</td>';
+                $iconshtml .= '<td class="controls cell c'.$columncount++.' icons">' . $this->get_icons($element) . '</td>';
             }
             $iconshtml .= '</tr>';
         }
@@ -1138,7 +1171,12 @@
         }
 
         // Init all icons
+        $edit_icon = '';
+
+        if ($element['type'] != 'categoryitem' && $element['type'] != 'courseitem') {
-        $edit_icon             = $this->gtree->get_edit_icon($element, $this->gpr);
+            $edit_icon             = $this->gtree->get_edit_icon($element, $this->gpr);
+        }
+
         $edit_calculation_icon = '';
         $show_hide_icon        = '';
         $lock_unlock_icon      = '';
Index: grade/report/grader/preferences.php
=========================================================
--- grade/report/grader/preferences.php	(revision 1.25.2.2)
+++ grade/report/grader/preferences.php	Mon Feb 09 08:35:59 CET 2009
@@ -66,21 +66,7 @@
     exit;
 }
 
-$strgrades = get_string('grades');
-$strgraderreport = get_string('modulename', 'gradereport_grader');
-$strgradepreferences = get_string('gradepreferences', 'grades');
-
-$navigation = grade_build_nav(__FILE__, $strgradepreferences, $courseid);
-
-print_header_simple($strgrades.': '.$strgraderreport . ': ' . $strgradepreferences,': '.$strgradepreferences, $navigation,
-                    '', '', true, '', navmenu($course));
-
-/// Print the plugin selector at the top
-print_grade_plugin_selector($course->id, 'report', 'grader');
-
-// Add tabs
-$currenttab = 'preferences';
-include('tabs.php');
+print_grade_page_head($courseid, 'report', 'grader', get_string('preferences', 'gradereport_grader'), false, '', true);
 
 // If USER has admin capability, print a link to the site config page for this report
 if (has_capability('moodle/site:config', $systemcontext)) {
Index: grade/report/overview/index.php
=========================================================
--- grade/report/overview/index.php	(revision 1.2.2.3)
+++ grade/report/overview/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -67,18 +67,6 @@
 }
 $USER->grade_last_report[$course->id] = 'overview';
 
-/// Build navigation
-$strgrades  = get_string('grades');
-$reportname = get_string('modulename', 'gradereport_overview');
-
-$navigation = grade_build_nav(__FILE__, $reportname, $course->id);
-
-/// Print header
-print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
-                    '', '', true, '', navmenu($course));
-
-/// Print the plugin selector at the top
-print_grade_plugin_selector($course->id, 'report', 'overview');
 
 if ($access) {
 
@@ -87,9 +75,7 @@
 
     // Create a report instance
     $report = new grade_report_overview($userid, $gpr, $context);
-
-    // print the page
-    print_heading(get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
+    print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
 
     if ($report->fill_table()) {
         echo $report->print_table(true);
@@ -97,6 +83,15 @@
 
 } else {
     // no access to grades!
+    /// Print header
+    /// Build navigation
+    $strgrades  = get_string('grades');
+    $reportname = get_string('modulename', 'gradereport_overview');
+
+    $navigation = grade_build_nav(__FILE__, $reportname, $course->id);
+    print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
+                        '', '', true, '', navmenu($course));
+
     echo "Can not view grades."; //TODO: localize
 }
 print_footer($course);
Index: grade/report/user/index.php
=========================================================
--- grade/report/user/index.php	(revision 1.26.2.9)
+++ grade/report/user/index.php	Mon Feb 09 08:35:59 CET 2009
@@ -71,19 +71,6 @@
 }
 $USER->grade_last_report[$course->id] = 'user';
 
-/// Build navigation
-$strgrades  = get_string('grades');
-$reportname = get_string('modulename', 'gradereport_user');
-
-$navigation = grade_build_nav(__FILE__, $reportname, $courseid);
-
-/// Print header
-print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
-                    '', '', true, '', navmenu($course));
-
-/// Print the plugin selector at the top
-print_grade_plugin_selector($courseid, 'report', 'user');
-
 
 if ($access) {
 
@@ -92,41 +79,48 @@
 
     if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
         /// Print graded user selector at the top
-        echo '<div id="graded_users_selector">';
-        print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid);
-        echo '</div>';
-        echo "<p style = 'page-break-after: always;'></p>";
+        $user_selector = '<div id="graded_users_selector">';
+        $user_selector .= print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid, true);
+        $user_selector .= '</div>';
+        $user_selector .= "<p style = 'page-break-after: always;'></p>";
 
         if ($userid === 0) {
             $gui = new graded_users_iterator($course);
             $gui->init();
+            // Add tabs
+            print_grade_page_head($courseid, 'report', 'user');
+
+            echo $user_selector.'<br />';
             while ($userdata = $gui->next_user()) {
                 $user = $userdata->user;
                 $report = new grade_report_user($courseid, $gpr, $context, $user->id);
                 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+
                 if ($report->fill_table()) {
-                    echo $report->print_table(true);
+                    echo '<br />'.$report->print_table(true);
                 }
                 echo "<p style = 'page-break-after: always;'></p>";
             }
             $gui->close();
         } elseif ($userid) { // Only show one user's report
             $report = new grade_report_user($courseid, $gpr, $context, $userid);
-            print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+            print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+            echo $user_selector;
             if ($report->fill_table()) {
-                echo $report->print_table(true);
+                echo '<br />'.$report->print_table(true);
-            } 
+            }
         }
-    } else { //Students will see just their own report 
+    } else { //Students will see just their own report
 
         // Create a report instance
         $report = new grade_report_user($courseid, $gpr, $context, $userid);
 
         // print the page
-        print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+        print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+        echo $user_selector;
 
         if ($report->fill_table()) {
-            echo $report->print_table(true);
+            echo '<br />'.$report->print_table(true);
         }
     }
 
Index: lang/en_utf8/grades.php
=========================================================
--- lang/en_utf8/grades.php	(revision 1.111.2.60)
+++ lang/en_utf8/grades.php	Mon Feb 09 09:36:36 CET 2009
@@ -11,6 +11,8 @@
 $string['addidnumbers'] = 'Add id numbers';
 $string['additem'] = 'Add grade item';
 $string['addoutcomeitem'] = 'Add outcome item';
+$string['addoutcome'] = 'Add an outcome';
+$string['addscale'] = 'Add a scale';
 $string['aggregateextracreditmean'] = 'Mean of grades (with extra credits)';
 $string['aggregatemean'] = 'Mean of grades';
 $string['aggregatemedian'] = 'Median of grades';
@@ -117,6 +119,7 @@
 $string['coursegradedisplaytype'] = 'Course grade display type';
 $string['coursegradedisplayupdated'] = 'The course grade display type has been updated.';
 $string['coursename'] = 'Course name';
+$string['coursescales'] = 'Course scales';
 $string['coursesettings'] = 'Course settings';
 $string['coursetotal'] = 'Course total';
 $string['createcategory'] = 'Create category';
@@ -144,7 +147,10 @@
 $string['editcalculationverbose'] = 'Edit calculation for $a->category$a->itemmodule $a->itemname';
 $string['editfeedback'] = 'Edit feedback';
 $string['editgrade'] = 'Edit grade';
+$string['editgradeletters'] = 'Edit grade letters';
+$string['editoutcome'] = 'Edit outcome';
 $string['editoutcomes'] = 'Edit outcomes';
+$string['editscale'] = 'Edit scale';
 $string['edittree'] = 'Categories and items';
 $string['editverbose'] = 'Edit $a->category$a->itemmodule $a->itemname';
 $string['enableajax'] = 'Enable AJAX';
@@ -332,6 +338,8 @@
 $string['myreportpreferences'] = 'My report preferences';
 $string['neverdeletehistory'] = 'Never delete history';
 $string['newcategory'] = 'New category';
+$string['newitem'] = 'New grade item';
+$string['newoutcomeitem'] = 'New outcome item';
 $string['newuserkey'] = 'New user key';
 $string['no'] = 'No';
 $string['nocategories'] = 'Grade categories could not be added or found for this course';
